/*
 * @Descripttion:
 * @version:
 * @Author: ybac
 * @Date: 2023-04-03 14:02:01
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-06-21 11:48:34
 */
import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from '@/config/router.config'
import { planManageMap } from '@/config/planManage'
import { apply } from '@/config/apply'
import { tanRouter } from '@/config/tanRouter'
import { appNewRoute } from '@/config/appNewRoute'
Vue.use(Router)
/* 给静态路由的meta添加appId，访问这些路由时会根据appId自动修改接口前缀 */
let appId = '0a8a9c9ed1124b85ac44fc4625226f1b'
let atherRoute = [...planManageMap, ...tanRouter, ...apply, ...appNewRoute]
atherRoute = atherRoute.map(item => {
  if (!item.meta.mgt) {
    item.meta.appId = appId
  }
  return item
})

const routers = [...constantRouterMap, ...atherRoute]
// router.beforeEach((to, from, next) => {
//   //这里能够跟踪路径的变化
//   console.log(from);
//   console.log(to);
//   //最后通过钩子继续页面的跳转
//   next(to);
// });
export default new Router({
  mode: 'hash', // 打包安卓
  // mode: 'history',// 打包H5
  // base: process.env.BASE_URL,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  },
  routes: routers
})
